package com.zwface.demo.function.login;

import android.os.Bundle;
import android.view.View;

import com.zwface.demo.databinding.ActivityLoginBinding;
import com.zwface.demo.function.login.mvvm.LoginViewModel;
import com.zwface.demo.R;
import com.zwface.demo.base.BaseActivity;
import com.zwface.demo.comm.comm;
import com.zwface.demo.function.web.WebActivity;

import androidx.lifecycle.ViewModelProviders;


public class LoginActivity extends BaseActivity<ActivityLoginBinding> implements View.OnClickListener {

    private static final String TAG = LoginActivity.class.getSimpleName();
    private LoginViewModel viewModel;

    @Override
    public int onLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public void onInitViewDataBinding(ActivityLoginBinding binding) {
        super.onInitViewDataBinding(binding);
        viewModel = ViewModelProviders.of(this).get(LoginViewModel.class);
        binding.setData(viewModel);
    }

    @Override
    public void onInitData(Bundle savedInstanceState) {
        super.onInitData(savedInstanceState);
    }

    @Override
    public void onInitListener() {
        super.onInitListener();
        binding.btnLogin.setOnClickListener(this);
        binding.tvRegister.setOnClickListener(this);
        binding.tvAgreement.setOnClickListener(this);
        binding.tvAgreement2.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.btn_login:
                viewModel.login();
                break;
            case R.id.tv_register:
                gotoActivityNotFinish(RegisterActivity.class,null);
                break;
            case R.id.tv_agreement:
                WebActivity.start(context,"用户协议",comm.AGREEMENT_TYPE_REGISTER);
                break;
            case R.id.tv_agreement2:
                WebActivity.start(context,"隐私政策",comm.AGREEMENT_TYPE_PRIVATE_POLICY);
                break;
        }
    }
}
